
package galaxy.app.network.rpc.handler;

import io.netty.channel.ChannelHandler.Sharable;
import io.netty.channel.ChannelHandlerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import galaxy.app.Galaxy;
import galaxy.app.log.LogHelper;
import galaxy.app.network.rpc.packet.ResponsePacket;
import galaxy.app.network.session.GateSession;
import galaxy.app.network.session.GateSessionServiceSystem;

/**
 */
@Sharable
public class ResponseToClientHandler extends BaseChannelHandler<ResponsePacket> {
    // private static Logger LOGGER = LoggerFactory.getLogger(ResponseToClientHandler.class);

    GateSessionServiceSystem gateSession;

    public ResponseToClientHandler() {
        super(ResponsePacket.class);
        gateSession = Galaxy.systems().get(GateSessionServiceSystem.class);
    }

    @Override
    protected void onChannelRead(ChannelHandlerContext ctx, ResponsePacket packet) {
        
        LogHelper.debug("<--- packet={}", packet);

        GateSession session = gateSession.getOnlineSession(packet.uid);
        if (session != null) {
            session.writeToClient(packet);
        }
    }
}
